package com.compomics.proteocloud.ui;

import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;

import javax.swing.*;
import java.awt.*;

/**
 * Extended StatusPanel for showing the project title, taxon database and number of running instances.
 *
 * @author Thilo Muth
 */
public class StatusPanel extends JPanel {

    /**
     * Project name label.
     */
    private JLabel projectNameLbl;

    /**
     *  Project field label.
     */
    private JLabel projectFieldLbl;

    /**
     * Content panel.
     */
    private JPanel contentPanel;

    /**
     * Taxon name label.
     */
    private JLabel taxonNameLbl;

    /**
     * Taxon field label.
     */
    private JLabel taxonFieldLbl;

    /**
     * Instances name label.
     */
    private JLabel instancesNameLbl;

    /**
     * Instances field label.
     */
    private JLabel instancesFieldLbl;

    public StatusPanel() {
        setLayout(new BorderLayout());
        setPreferredSize(new Dimension(getWidth(), 30));
        initComponents();
    }

    /**
     * Initializes the components.
     */
    private void initComponents(){
        contentPanel = new JPanel();
        contentPanel.setOpaque(false);
        contentPanel.setLayout(new FormLayout("20dlu, p, 5dlu, p, 10dlu, p, 10dlu, p, 5dlu, p, 10dlu, p, 10dlu, p, 5dlu, p, 5dlu", "4dlu, fill:10dlu, 2dlu"));

        projectNameLbl = new JLabel("Selected Project:");
        projectNameLbl.setFont(new Font("Arial", Font.PLAIN, 12));
        projectFieldLbl = new JLabel("None");
        projectFieldLbl.setFont(new Font("Arial", Font.PLAIN, 12));

        taxonNameLbl = new JLabel("Taxon Database:");
        taxonNameLbl.setFont(new Font("Arial", Font.PLAIN, 12));
        taxonFieldLbl = new JLabel("None");
        taxonFieldLbl.setFont(new Font("Arial", Font.PLAIN, 12));

        instancesNameLbl = new JLabel("No. Running Instances:");
        instancesNameLbl.setFont(new Font("Arial", Font.PLAIN, 12));
        instancesFieldLbl = new JLabel("0");
        instancesFieldLbl.setFont(new Font("Arial", Font.PLAIN, 12));

        CellConstraints cc = new CellConstraints();
        contentPanel.add(projectNameLbl, cc.xy(2, 2));
        contentPanel.add(projectFieldLbl, cc.xy(4, 2));
        contentPanel.add(new SeparatorPanel(Color.GRAY, Color.WHITE), cc.xy(6, 2));
        contentPanel.add(taxonNameLbl, cc.xy(8, 2));
        contentPanel.add(taxonFieldLbl, cc.xy(10, 2));
        contentPanel.add(new SeparatorPanel(Color.GRAY, Color.WHITE), cc.xy(12, 2));
        contentPanel.add(instancesNameLbl, cc.xy(14, 2));
        contentPanel.add(instancesFieldLbl, cc.xy(16, 2));
        add(contentPanel, BorderLayout.CENTER);
    }

    /**
     * Used to separate the sections of the StatusPanel.
     *
     * @author Thilo Muth
     */
    private class SeparatorPanel extends JPanel {

        /**
         * Left color.
         */
        private Color leftColor;

        /**
         * Right color.
         */
        private Color rightColor;

        /**
         * Constructos the Separator Panel with left and right color.
         * @param leftColor Left color.
         * @param rightColor Right color.
         */
        public SeparatorPanel(Color leftColor, Color rightColor) {
            this.leftColor = leftColor;
            this.rightColor = rightColor;
            setOpaque(false);
        }

        /**
         * Overrides the standard paintComponent method.
         * @param g Graphics object.
         */
        protected void paintComponent(Graphics g){
            g.setColor(leftColor);
            g.drawLine(0, 0, 0, getHeight());
            g.setColor(rightColor);
            g.drawLine(1, 0, 1, getHeight());
        }
    }

    /**
     * Returns the project field label.
     * @return projectFieldLbl The project field label.
     */
    public JLabel getProjectFieldLabel() {
        return projectFieldLbl;
    }

    /**
     * Returns the taxon field label.
     * @return taxonFieldLbl The taxon field label.
     */
    public JLabel getTaxonFieldLabel() {
        return taxonFieldLbl;
    }

    /**
     * Returns the number of running instances.
     * @return instanceFieldLbl The instances field label.
     */
    public JLabel getInstancesFieldLabel() {
        return instancesFieldLbl;
    }
}

